package com.jiezheng.huinong.interceptor;

import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor extends AbstractInterceptor {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 1407510631751748820L;

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {

		//检查session中是否有user标志
		Map<?, ?> session = invocation.getInvocationContext().getSession();
		
		String username = (String)session.get("user");
		if(username!= null && username.length() > 0 ){
			//存在用户
			System.out.println("already login!");
			return invocation.invoke();
		}
		else{
			//终止login，退回到主登录界面
			System.out.println("no login, forward login page!);");
			return Action.LOGIN;
		}
	}

}
